package cn.zysuyuan.item.controller;

import cn.zysuyuan.common.entity.PageResult;
import cn.zysuyuan.item.entity.Medicinal;
import cn.zysuyuan.item.entity.MedicinalInf;
import cn.zysuyuan.item.service.WxMedicinalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * @author flypig
 * @version 1.0
 * @date 2019-12-12 1:56
 */

@Api(tags = "小程序中药材信息")
@Controller
@RequestMapping("wxmedicinal")
public class WxMedicinalController {

    @Autowired
    private WxMedicinalService medicinalService;

    @ApiOperation(value = "小程序首页中药材信息", tags = "小程序首页中药材信息")
    @GetMapping("medicinaldata")
    public ResponseEntity<PageResult<MedicinalInf>> selectMedicinal(@RequestParam(value = "mName") String mName) {
        PageResult<MedicinalInf> result = this.medicinalService.select(mName);
        if (CollectionUtils.isEmpty(result.getRows())) {
            return ResponseEntity.notFound().build();
        }
        return ResponseEntity.ok(result);
    }

    @ApiOperation(value = "单个药材详情信息", tags = "单个药材详情信息")
    @GetMapping("medicinaldetail")
    public ResponseEntity<PageResult<MedicinalInf>> selectMedicinalDetail(@RequestParam("id") String id) {
        PageResult<MedicinalInf> result = this.medicinalService.selectDetail(id);
        if (CollectionUtils.isEmpty(result.getRows())) {
            return ResponseEntity.notFound().build();
        }
        return ResponseEntity.ok(result);
    }
}
